package model

import "litter-api/app/util/pool"

// 微信用户表
type WxUser struct {
	//gorm.Model
	Openid    string `json:"openid"`
	Nickname  string `json:"nickname"`
	Avatarurl string `json:"avatarurl"`
	Gender    uint   `json:"gender"`
	Country   string `json:"country"`
	Province  string `json:"province"`
	City      string `json:"city"`
	Language  string `json:"language"`
	Mobile    string `json:"mobile"`
	Telnum    string `json:"telnum"`
	BaseModel `gorm:"embedded"`
	Wallet    WxWallet   `gorm:"foreignKey:UserId"`
	UserAddr  []UserAddr `gorm:"foreignKey:UserId"`
}

var (
	User *WxUser
)

func (w *WxUser) GetTable() string {
	return "fb_wx_user"
}

func SetUser(openid string) *WxUser {
	pool.Db.Table(User.GetTable()).Where("openid = ?", openid).First(&User)

	return User
}
